package demo.day11


// Kotlin 语言的泛型类型约束
fun main() {
//    var p1 = MyAnyClass("Kiki")
    var p2 = PersonClass("Kiki")
    var p3 = StudentClass("Kiki")
    var p4 = TeacherClass("Kiki")
//    var p5 = DogClass("Kiki")
//    println(KtBaseDay11_01(p1).getObj())
    println(KtBaseDay11_01(p2).getObj())
    println(KtBaseDay11_01(p3).getObj())
    println(KtBaseDay11_01(p4).getObj())
//    println(KtBaseDay11_01(p5).getObj())
}

open class MyAnyClass(name: String) // 祖宗类 顶级父类

open class PersonClass(name: String) : MyAnyClass(name) // 父类

class StudentClass(name: String) : PersonClass(name) // 实现子类
class TeacherClass(name: String) : PersonClass(name) // 实现子类
class DogClass(name: String) // 其他类

// T:PersonClass 代表着T为Person的子类
class KtBaseDay11_01<T : PersonClass>(val inputValue: T, private val isReal: Boolean = true) {
    fun getObj() = inputValue.takeIf { isReal }
}